import axios, { AxiosRequestConfig } from "axios";
import { getBaseUrl } from "@bis/utils/constants";

// 不同环境不同的请求接口
const baseUrl = getBaseUrl() as string;

// axios的请求配置
const config: AxiosRequestConfig = {
  baseURL: baseUrl,
  withCredentials: true,
  proxy: false,
  maxRedirects: 0,
};

const request = axios.create({
  baseURL: config.baseURL,
  timeout: 60000,
  headers: {
    "Content-Type": "application/json;charset=UTF-8",
    "Access-Control-Max-Age": 3600,
  },
});

// 请求处理拦截器
request.interceptors.request.use(
  (config: any) => {
    return config;
  },
  (error) => {
    return Promise.reject();
  }
);

// 返回结果拦截器
request.interceptors.response.use(
  (res) => {
    return Promise.resolve(res.data);
  },
  (err) => {
    return Promise.resolve(err);
  }
);

export default request;
